<template>
  <a-modal
    :title="title"
    :width="600"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="locationName"
          label="地点名称">
          <a-input placeholder="请输入地点名称" v-model="model.locationName"/>
        </a-form-model-item>
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="longitude"
          label="经度">
          <a-input placeholder="请输入经度" v-model="model.longitude"/>
        </a-form-model-item>
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="latitude"
          label="纬度">
          <a-input placeholder="请输入纬度" v-model="model.latitude"/>
        </a-form-model-item> <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="openingTours"
          label="营业时间">
          <a-input placeholder="请输入营业时间" v-model="model.openingTours"/>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>
<script>
  import { addBladeUmbrellaLocation, updateBladeUmbrellaLocation } from "@/api/umbrella/BladeUmbrellaLocation";
  export default {
    name: 'bladeDevice',
    components: {},
    data() {
      return {
        value: 1,
        title: '操作',
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        confirmLoading: false,
        validatorRules: {
          locationName: [{ required: true, message: '请输入地点名称!' }],
          longitude: [{ required: true, message: '请输入经度!' }],
          latitude: [{ required: true, message: '请输入纬度!' }],
          openingTours: [{ required: true, message: '请输入营业时间!' }],
        },
      }
    },
    created() {
    },
    methods: {
      add() {   //添加
        this.edit({
          status: 0
        })
      },
      handleChange(value) {
        this.model.status = value
      },
      change(e){
        console.log(e.target.value);
      },
      edit(record) { //修改
        if (record.id) {
          this.visiblekey = true
        } else {
          this.visiblekey = false
        }
        this.model = Object.assign({}, record)
        this.visible = true
      },
      // 确定
      handleOk() {
        const that = this
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true
            if (this.model.id != null) {
              updateBladeUmbrellaLocation(this.model).then(response => {
                if (response.success) {
                  that.$message.success(response.msg)
                  that.$emit('ok')
                } else {
                  that.$message.warning(response.msg)
                }
              }).finally(() => {
                that.confirmLoading = false
                that.close()
              });
            }else{
              addBladeUmbrellaLocation(this.model).then(response => {
                if (response.success) {
                  that.$message.success(response.msg)
                  that.$emit('ok')
                } else {
                  that.$message.warning(response.msg)
                }
              }).finally(() => {
                that.confirmLoading = false
                that.close()
              });;
            }
          } else {
            return false;
          }
        })
      },
      // 关闭
      handleCancel() {
        this.close()
      },
      close() {
        this.$emit('close')
        this.fileList = []
        this.visible = false
        this.$refs.form.resetFields();
      },
    }
  }
</script>

<style scoped>

</style>